package com.huayi.breakpoint_continuation_interface.utils;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


public class ThreadPoolUtil {
    private static ThreadPoolExecutor threadPoolExecutor;

    //获取线程池
    public static ThreadPoolExecutor getInstance() {
        //多线程下需要在加一层判断
        if (threadPoolExecutor == null) {
            //加锁，否则存在线程安全问题
            synchronized (ThreadPoolExecutor.class) {
                if (threadPoolExecutor == null) {
                    System.out.println(">>>>>>>>>>>>创建线程池对象<<<<<<<<<<<<");
                    threadPoolExecutor = new ThreadPoolExecutor(4, 20, 300, TimeUnit.SECONDS,
                            new LinkedBlockingQueue<Runnable>(Integer.MAX_VALUE));
                }
            }
        }
        return threadPoolExecutor;

    }

}
